package com.iwhalecloud.citybrain.flow.platform.manager.application.service.impl;

import com.fasterxml.jackson.databind.JsonNode;
import com.iwhalecloud.citybrain.flow.platform.manager.application.common.context.FlowElementProcessContext;
import com.iwhalecloud.citybrain.flow.platform.manager.application.service.CustomPropertiesProcessor;
import com.iwhalecloud.citybrain.flow.platform.manager.domain.repository.FlowReNodeAuthRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 处理properties->nodeAuth属性
 *
 * @author lilh
 * @date 2020/11/16 16:34
 */
@Service
public class NodeAuthCustomPropertiesProcessor implements CustomPropertiesProcessor {

    @Autowired
    private FlowReNodeAuthRepository flowReNodeAuthRepository;

    @Override
    public boolean support(JsonNode elementNode) {
        JsonNode properties = elementNode.get("properties");
        if (nonNull(properties)) {
            return nonNull(properties.get("nodeAuth"));
        }
        return false;
    }

    @Override
    public void process(FlowElementProcessContext context) {
        flowReNodeAuthRepository.saveNodeAuth(context.getDeployId(), context.getNodeCode(), context.getElementNode().get("properties").get("nodeAuth"));
    }
}
